//
//  TSRechargeHeaderView.swift
//  TSProfitProject
//
//  Created by TMS on 2019/11/4.
//  Copyright © 2019 TMS. All rights reserved.
//

import UIKit

class TSRechargeHeaderView: UIView {
    
    var avatar : UIImageView!
    var nameLabel : UILabel!
    var identifyLabel : UILabel!
    var storeLabel : UILabel!

    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = WHITE_COLOR
        configViews()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func refreshHeaderView() {
        storeLabel.text = "中心钱包：￥"+String.init(format: "%.2f", TSLoginManager.shared._usermodel?.zhongxin ?? 0)
    }
    
    func configViews() {
        
        let containerView = UIView.init()
        containerView.backgroundColor = BASE_PURPLE_COLOR
        containerView.layer.cornerRadius = 10
        containerView.layer.masksToBounds = true
        self.addSubview(containerView)
        containerView.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.top.equalTo(17)
            make.width.equalTo(SCREEN_WIDTH - 2*12)
            make.height.equalTo(159)
        }
        
        avatar = UIImageView.init()
        avatar.image = UIImage(named: "general_avatar_default")
        avatar.backgroundColor = WHITE_COLOR
        avatar.layer.cornerRadius = 30
        avatar.layer.masksToBounds = true
        containerView.addSubview(avatar)
        avatar.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.top.equalToSuperview().offset(15)
            make.size.equalTo(CGSize(width: 60, height: 60))
        }
        
        nameLabel = UILabel.init()
        nameLabel.text = TSLoginManager.shared._usermodel?.username ?? "暂未设置"
        nameLabel.textColor = WHITE_COLOR
        nameLabel.font = UIFont.systemFont(ofSize: 16, weight: .medium)
        containerView.addSubview(nameLabel)
        nameLabel.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.top.equalTo(avatar.snp_bottom).offset(5)
        }
        
        identifyLabel = UILabel.init()
        identifyLabel.text = "ID\(TSLoginManager.shared._usermodel?.user_id ?? 0)"
        identifyLabel.textColor = WHITE_COLOR
        identifyLabel.font = UIFont.systemFont(ofSize: 12)
        containerView.addSubview(identifyLabel)
        identifyLabel.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.top.equalTo(nameLabel.snp_bottom).offset(11)
        }
        
        storeLabel = UILabel.init()
        storeLabel.text = "中心钱包：￥"+String.init(format: "%.2f", TSLoginManager.shared._usermodel?.zhongxin ?? 0)
        storeLabel.textColor = WHITE_COLOR
        storeLabel.font = UIFont.systemFont(ofSize: 12)
        containerView.addSubview(storeLabel)
        storeLabel.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.top.equalTo(identifyLabel.snp_bottom).offset(11)
        }
        
        let line = UIView.init()
        line.backgroundColor = BASE_LINE_COLOR
        self.addSubview(line)
        line.snp.makeConstraints { (make) in
            make.left.right.bottom.equalToSuperview()
            make.height.equalTo(1)
        }
    }

}
